package vidas;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;

public abstract class Figura implements KeyListener, Runnable{
    
    protected Integer x, y, w, h;
    protected Color color;
    protected Integer vida=10;
     protected Integer vida2=1;
    protected Integer dx=5;
    protected Integer dy=5;
    protected Lienzo lienzo;
    protected Thread hilo;
    protected Integer periodo=50;
    public int score;
    
    // paul y martin se la comennnnn!!! putasosss
    protected Figura(Integer x0, Integer y0, Integer w0, Integer h0, Color c, 
            Lienzo l) {
        x=x0;
        y=y0;
        w=w0;
        h=h0;
        color=c;
        lienzo=l;
        
    }
    public void ira(Integer x0, Integer y0){       
        
        try {
            x = x0;
            y = y0;
            lienzo.repaint();
            for (i = 0; i < lienzo.getF().size(); i++) {
                        getClass().getMethod("colisiono" + Boolean.valueOf(this.rect().
                        intersects(lienzo.getF().get(i).rect())).toString(), (Class[]) null).
                        invoke(this, (Object[]) null);
            }
        } catch (Exception ex) {
        }
    }
    public int i;
    public void colisionofalse(){} 
    public void colisionotrue(){               
                   
    try {          
            getClass().getMethod("colisionosolo" + Boolean.valueOf(this.equals(lienzo.getF().get(i))).toString(), (Class[]) null).
                    invoke(this, (Object[]) null);      
        } catch (Exception ex) {}        
    }
      
    public void colisionosolotrue(){}
    public void colisionosolofalse(){
     this.colisionoCon(lienzo.getF().get(i)); 
     }
   
    protected Rectangle rect(){
        Rectangle r=  new Rectangle( x, y, w, h);     
        return r;
    }
    
    public void ira(){
         lienzo.repaint();
           
            for (i = 0; i < lienzo.getF().size(); i++) {
        try {
                getClass().getMethod("colisiono" + Boolean.valueOf(this.rect().
                        intersects(lienzo.getF().get(i).rect())).toString(), (Class[]) null).
                        invoke(this, (Object[]) null);
        }
        catch (Exception ex) {
        }
       }            
    }
  
     public abstract void dibujate(Graphics g); 
    
  

     
    public abstract void colisionoCon(Figura c);   
    public abstract void colisionoCon(Movil c);
     
    public abstract void colisionoCon(Pared c);
    public abstract void colisionoCon(Base c);
    
    @Override
    public String toString(){
        return "["+x+" "+y+" "+w+" "+h+"]";
    }

    public Integer getDx() {
        return dx;
    }

    public Integer getDy() {
        return dy;
    }

    public void setDx(Integer dx) {
        this.dx = dx;
    }

    public void setDy(Integer dy) {
        this.dy = dy;
    }
    
    public void inicioHilo(){
       this.hilo=new Thread(this);
       hilo.start();
    }
    
    
    public void run(){
    while(true){
            try {
                this.hilo.sleep(periodo);
                this.ira(x+dx,y+dy);
            } catch (InterruptedException ex) { }
    }
    
    }
    
    
}
